<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>报销申请</title>
		<script src="js/mui.min.js"></script>
		<link href="css/mui.min.css" rel="stylesheet" />
		<script type="text/javascript" src="../js/jquery.min.js" charset="utf-8"></script>
		<link href="../css/reimbursementDetalis.css" rel="stylesheet" />
		<script type="text/javascript" charset="utf-8">
			$(function() {
				var userId = localStorage.getItem("userId");
				var tkcId = localStorage.getItem("tkcId");
				var token = localStorage.getItem("token");
				var ip = localStorage.getItem("ip");
				$.ajax({
					type: 'post', //类型
					url: ip + 'workFlow/details', //请求路径
					contentType: 'application/x-www-form-urlencoded', //默认
					dataType: 'json', //返回数据类型  可以是text：字符串  可以是json：json对象
					data: {
						'userId': userId,
						'taskprocessInstanceId': tkcId,
						'token': token,
					}, //数据
					success: function(result) {
						if(result.code == 200) {
							document.getElementById('userName').innerText = result.data.userName;
							document.getElementById('money').innerText = result.data.money;
							document.getElementById('notes').innerText = result.data.notes;
							document.getElementById('reason').innerText = result.data.reason;
							document.getElementById('createTime').innerText = result.data.createTime;
							var statusName = result.data.statusName;
							var imagePath = result.data.imagePath;
							var imagePathArray = imagePath.split(',');
							var txts = "";
							for(var Key in imagePathArray) {
								txts = txts + '<img src="' + imagePathArray[Key] + '" style="width: 30%; height: 80px;" />';
							}
							$(".imgdiv").append(txts);
							if("老板审批" == statusName) {
								hideApproval();
							}else if("确认收款" == statusName) {
								hideSuccess();
							}
						} else {
							alert('获取数据异常,请重新登录');
							//window.location.href = 'Login.html';
						}
					},
					error: function(data) { //若果传过来的数据为空
					}
				});
			});

			function hideApproval() {
				$(".approval").show();
			}
			function hideSuccess() {
				$(".success").show();
			}

			/**
			 * 办理任务
			 * @param {Object} taskId
			 */
			function complete(variables) {
				var ip = localStorage.getItem("ip");
				var taskId = localStorage.getItem("taskId");
				var procInsId = localStorage.getItem("processInstanceId");
				// 转换JSON为字符串
				var keys = "",
					values = "",
					types = "";
				if(variables) {
					$.each(variables, function(idx) {
						if(keys != "") {
							keys += ",";
							values += ",";
							types += ",";
						}
						keys += this.key;
						values += this.value;
						types += this.type;
					});
				}
				// 发送任务完成请求
				//				loadi = layer.load(2, {
				//					shade: layerLoadShade,
				//					time: layerLoadMaxTime
				//				});
				$.post(ip + 'workFlow/complete/', {
					taskId: taskId,
					procInsId: procInsId,
					"comment": $('#comment').val(),
					"vars.keys": keys,
					"vars.values": values,
					"vars.types": types
				}, function(data) {
					if(data == 'T') {
						window.location.href = 'approvalProcess.html';
					} else {
						alert("操作失败");
					}
				});
			}

			function goBackToList() {
				//window.close();
				history.go(-1);
			}
		</script>
	</head>

	<body style="background: #d9d9d9;">
		<form action="#" method="post" id="dataForm" enctype="multipart/form-data">
			<div style=" background: white; width: 90%; margin-left: 5%;margin-top: 10%; box-shadow:1px 2px 1px 1px #aaa;-webkit-border-radius: 10px;">
				<br />
				<font>报销人：</font>
				<font id="userName">李豆豆</font><br/><br />
				<font>报销额：</font>
				<font id="money">100000</font><br/><br />
				<font>报销描述：</font>
				<font id="notes">李豆豆</font><br /><br />
				<font>报销用途：</font>
				<font id="reason">李豆豆</font><br /><br />
				<font>申请时间：</font>
				<font id="createTime">李豆豆</font><br /><br />
				<div class="imgdiv" style="margin-left: 5%;">
				</div><br />
				<div class="approval" style="display:none;">
					<input onclick="complete([{key: 'boosPass',value: true,type: 'B'}])" type="button" value="同意" style=" font-weight:bold; font-size: calc(17vw/3.75); -webkit-border-radius: 10px; width: 40%;height: 40px;margin: 5%; margin-bottom:15%;background: #33ff99;color: white;" />
					<input onclick="complete([{key: 'boosPass',value: true,type: 'B'}])" type="button" value="拒绝" style=" font-weight:bold; font-size: calc(17vw/3.75); -webkit-border-radius: 10px; width: 40%;height: 40px;margin: 3%;background: #33ff99;color: white;" />
				</div>
				<div class="success" style="display:none;">
					<input onclick="complete([{key: 'boosPass',value: true,type: 'B'}])" type="button" value="确定收款" style=" font-weight:bold; font-size: calc(17vw/3.75); -webkit-border-radius: 10px; width: 90%;height: 40px;margin: 5%; margin-bottom:15%;background: #6fa8dc;color: white;" />
				</div>
			</div>
		</form>
	</body>

</html>